#!/bin/sh /etc/rc.common
# Copyright (C) 2007-2014 OpenWrt.org

## hyphop ##

START=93
USE_PROCD=1

PROG=/usr/bin/mpd
CONFIGFILE=/etc/mpd.conf
NICEPRIO=-10

#TODO: Add uci config - nice, config

start_service() {
	#create mpd directories from config
#	local pld=`grep ^playlist_directory "$CONFIGFILE" | cut -d "\"" -f 2 | sed "s/~/\/root/g"`
#	if [ ! -d $pld ]; then
#		mkdir -m 0755 -p $pld
#	fi

	local lport=`grep ^port "$CONFIGFILE" | cut -d "\"" -f 2`
	[ -z $lport ] && lport=6600

	procd_open_instance
	procd_add_mdns "mpd" "tcp" "$lport"
	procd_set_param command "$PROG" --no-daemon "$CONFIGFILE"
	# Give MPD some real-time priority
	procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
	procd_set_param nice "$NICEPRIO"

	procd_set_param user root # run service as user nobody
	procd_set_param stdout 1 # forward stdout of the command to logd
	procd_set_param stderr 1 # same for stderr

#	procd_set_param respawn
	procd_close_instance
}
